import React from 'react';
import { connect } from 'dva';
import _ from 'lodash';
/*
 * root
 * admin
 * boss 老板
 * operator 运营
 * supervisor 督导
 * manager   店长
 * salesman  导购
 * */
class EnsureLoggedInContainer extends React.Component {
  static defaultProps = {
    isShow: [],
  };

  render() {
    const { roles } = this.props.user;
    const { isShow } = this.props;
    const result = _.some(isShow, (v) => {
      return _.includes(roles, v);
    });
    if (result) {
      return this.props.children;
    }
    return this.props.content || null;
  }
}

function mapStateToProps(state, ownProps) {
  return {
    user: state.auth.currentUser,
  };
}

export default connect(mapStateToProps)(EnsureLoggedInContainer);
